package com.axt.dbaudit.unitTest;

import com.axt.util.DateTime;

public class FuncTest {
	public static void main(String[] args) throws Exception {
		System.out.println(DateTime.UnixToStr("1334309647"));
		System.out.println(DateTime.UnixTimestamp("2012-04-13 17:34:07"));
		long ip = ipToLong("192.168.1.111");
		System.out.println(longToIP(ip));

	}

	public static long ipToLong(String ip) {
		long[] lIp =new long[4];
		int pos1 = ip.indexOf(".");
		int pos2 = ip.indexOf(".", pos1 + 1);
		int pos3 = ip.indexOf(".", pos2 + 1);
		
		lIp[0] = Long.parseLong(ip.substring(0, pos1));
		lIp[1] = Long.parseLong(ip.substring(pos1+1, pos2));
		lIp[2] = Long.parseLong(ip.substring( pos2+1, pos3));
		lIp[3] = Long.parseLong(ip.substring(pos3+1));
		return (lIp[0] << 24) + (lIp[1] << 16) + (lIp[2] << 8) + lIp[3];
	}
	
	public static String longToIP(long aIP){
	  StringBuffer sbBuffer = new StringBuffer("");
	  // 直接右移24位
	  sbBuffer.append(String.valueOf((aIP >>>24)));
	  sbBuffer.append(".");
	  // 将高8位置0，然后右移16位
	  sbBuffer.append(String.valueOf(((aIP&0x00FFFFFF) >>>16)));
	  sbBuffer.append(".");
	  // 将16位置0，然后右移8位
	  sbBuffer.append(String.valueOf(((aIP&0x0000FFFF) >>>8)));
	  sbBuffer.append(".");
	  // 将高24位置0
	  sbBuffer.append(String.valueOf((aIP &0x000000FF)));

       return sbBuffer.toString();
	  
	  
	}
}
